$(function () {
	vm.mentorId = getQueryString("id");
	if (StringUtils.isEmpty(vm.mentorId )) {
		$("#loginInfo").hide();
	} else {
		vm.getInfo(vm.mentorId);
	}
	
	$("#edit-form").validate();
});

var vm = new Vue({
	el:'#mapp',
	data:{
		title: "编辑导师信息",
		bsnMentor: {},
		mentorId: ""
	},
	methods: {
		saveOrUpdate: function (event) {
			if (!$("#edit-form").valid()) {
				return;
			}
			var thisUrl;
			if (StringUtils.isEmpty(vm.bsnMentor.id)) {
				thisUrl = ajaxServerUrlG("bsnmentor/save");
			} else {
				thisUrl = ajaxServerUrlG("bsnmentor/update");
			}
			$.ajax({
				type: "POST",
			    url: thisUrl,
                contentType: "application/json",
			    data: JSON.stringify(vm.bsnMentor),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功');
						if (r.bsnMentor) {
							vm.bsnMentor = r.bsnMentor;
							$("#loginInfo").show();
						}
					}else{
						alert(r.msg);
					}
				}
			});
		},
		getInfo: function(id){
			// console.log(StringUtils.isEmpty(id));
			
			if (StringUtils.isEmpty(id)) return;
			var thisUrl = ajaxServerUrlG("bsnmentor/info/" + id);
			$.get(thisUrl, function(r){
					if(r.code === 0){
                		vm.bsnMentor = r.bsnMentor;
					}else{
						alert(r.msg);
					} 
            });
		},
		gotoLoginInfo: function() {
			var gotoUrl = "msLoginUserEdit.html?loginId=" + vm.bsnMentor.loginId +  
			    "&mobile=" + vm.bsnMentor.shouji + 
				"&username=" + vm.bsnMentor.xingm + 
				"&userType=mentor&relationId=" + vm.bsnMentor.id;
			console.log(encodeURI(encodeURI(gotoUrl)));
			window.location = encodeURI(encodeURI(gotoUrl));
		},
		openFileSelector: function() {
			if (StringUtils.isEmpty(vm.bsnMentor.id)) {
				alert("请先保存");
				return;
			}
			var uploadUrl = getUploadFileUrl() + 
				"&objectType=mentor&busType=lvli&formId=" + vm.bsnMentor.id;
			console.log(uploadUrl);
			//区分IOS和android的处理
			if (/iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase())) {
				uploadFileProxy(uploadUrl);
			} else {
				window.jsInvoke.uploadFileProxy(uploadUrl);
			}
		},
		preView: function(jianliurl) {
			if (StringUtils.isEmpty(jianliurl)) {
				return;
			}
			console.log("附件=" + jianliurl);
			var uploadUrl = getDownFileUrl(jianliurl);
			if (/iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase())) {
				openFileView(uploadUrl);
			} else {
				window.jsInvoke.openFileView(uploadUrl);
			}
		}
	}
});

//文件上传回调方法。
function uploadCallBack(fileName) {
	//上传后，刷新文件Id
	// console.log(fileName);
	if (/iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase())) {
		setTimeout("vm.getInfo(vm.mentorId);", 300);
	} else {
		vm.getInfo(vm.mentorId);
	}
	
}
